﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Search
{
    public partial class Form1 : Form
    {
        private SearchManager dulieu;
        public Form1()
        {
            InitializeComponent();
            dulieu = new SearchManager();
        }

        private void textBox1_KeyUp(object sender, KeyEventArgs e)
        {
            string input = textBox1.Text;
            if (input.Length >= 2)
            {
                var goiy =dulieu.GoiY(input,false);
                label3.Text = "";
                 foreach (var item in goiy)
                    {
                        label3.Text += " - "+ item;
                    }
                if (dulieu.objectText.Count > 0)
                {
                    label1.Text = "";
                    label2.Text = "";
                    var datacity = dulieu.objectText.FirstOrDefault(x=>x.type == 0);
                    if (datacity != null)
	                {
		                 label1.Text = datacity.text;
	                }  

                     var datadistrict = dulieu.objectText.FirstOrDefault(x=>x.type == 1);
                    if (datadistrict != null)
	                {
		                 label2.Text = datadistrict.text;
	                }
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string input = textBox1.Text;
            var goiy = dulieu.GoiY(input,true);
            if (dulieu.objectText.Count > 0)
            {
                label1.Text = "";
                label2.Text = "";
                var datacity = dulieu.objectText.FirstOrDefault(x => x.type == 0);
                if (datacity != null)
                {
                    label1.Text = datacity.text;
                }

                var datadistrict = dulieu.objectText.FirstOrDefault(x => x.type == 1);
                if (datadistrict != null)
                {
                    label2.Text = datadistrict.text;
                }
            }
        }

    }

    public class Bigo
    {
        public Bigo()
        {
            doan = new List<Doan>();
        }
        public List<Doan> doan { get; set; }
    }

    public class Doan
    {
        public string text { get; set; }

        public int start { get; set; }

        public int end { get; set; }

        public int status { get; set; }//0 la city, 1 la  districts
    }
    public class City
    {
        public City()
        {
            items = new List<Value>
            {
                new Value
                {
                    key = "ha noi",
                    name = "Hà Nội"
                },
                new Value
                {
                    key = "da nang",
                    name = "Đà Nẵng"
                },
                new Value
                {
                    key = "tp hcm",
                    name = "TP HCM"
                }
            };
        }

        public List<Value> items { get; set; }
    }

    public class District
    {
        public District()
        {
            items = new List<Value>
            {
                new Value
                {
                    key = "thanh xuan",
                    name = "Thanh Xuân"
                },
                new Value
                {
                    key = "ha dong",
                    name = "Hà Đông"
                },
                new Value
                {
                    key = "sai gon",
                    name = "Sài Gòn"
                },
                new Value
                {
                    key = "da nang",
                    name = "Đà Nẵng"
                }
            };
        }

        public List<Value> items { get; set; }
    }

    public class Value
    {
        public string name { get; set; }
        public string key { get; set; }
    }
}
